package com.ruoyi.find.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.find.domain.FurnitureType;
import com.ruoyi.find.service.IFurnitureTypeService;

/**
 * 家具类型Controller
 * 
 * @author ruoyi
 * @date 2025-05-24
 */
@RestController
@RequestMapping("/find/furnitureType")
public class FurnitureTypeController extends BaseController
{
    @Autowired
    private IFurnitureTypeService furnitureTypeService;

    /**
     * 查询家具类型列表
     */
    @PreAuthorize("@ss.hasPermi('find:furnitureType:list')")
    @GetMapping("/list")
    public TableDataInfo list(FurnitureType furnitureType)
    {
        startPage();
        List<FurnitureType> list = furnitureTypeService.selectFurnitureTypeList(furnitureType);
        return getDataTable(list);
    }

    /**
     * 导出家具类型列表
     */
    @PreAuthorize("@ss.hasPermi('find:furnitureType:export')")
    @Log(title = "家具类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FurnitureType furnitureType)
    {
        List<FurnitureType> list = furnitureTypeService.selectFurnitureTypeList(furnitureType);
        ExcelUtil<FurnitureType> util = new ExcelUtil<FurnitureType>(FurnitureType.class);
        util.exportExcel(response, list, "家具类型数据");
    }

    /**
     * 获取家具类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('find:furnitureType:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return AjaxResult.success(furnitureTypeService.selectFurnitureTypeByTypeId(typeId));
    }

    /**
     * 新增家具类型
     */
    @PreAuthorize("@ss.hasPermi('find:furnitureType:add')")
    @Log(title = "家具类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FurnitureType furnitureType)
    {
        return toAjax(furnitureTypeService.insertFurnitureType(furnitureType));
    }

    /**
     * 修改家具类型
     */
    @PreAuthorize("@ss.hasPermi('find:furnitureType:edit')")
    @Log(title = "家具类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FurnitureType furnitureType)
    {
        return toAjax(furnitureTypeService.updateFurnitureType(furnitureType));
    }

    /**
     * 删除家具类型
     */
    @PreAuthorize("@ss.hasPermi('find:furnitureType:remove')")
    @Log(title = "家具类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(furnitureTypeService.deleteFurnitureTypeByTypeIds(typeIds));
    }

    /**
     * 查询所有启用的家具类型
     */
    @GetMapping("/allEnabled")
    public AjaxResult selectAllEnabledFurnitureTypes()
    {
        List<FurnitureType> list = furnitureTypeService.selectAllEnabledFurnitureTypes();
        return AjaxResult.success(list);
    }

    /**
     * 根据父类型ID查询子类型
     */
    @GetMapping("/childTypes/{parentId}")
    public AjaxResult selectChildTypesByParentId(@PathVariable Long parentId)
    {
        List<FurnitureType> list = furnitureTypeService.selectChildTypesByParentId(parentId);
        return AjaxResult.success(list);
    }

    /**
     * 启用家具类型
     */
    @PreAuthorize("@ss.hasPermi('find:furnitureType:edit')")
    @Log(title = "家具类型", businessType = BusinessType.UPDATE)
    @PutMapping("/enable/{typeId}")
    public AjaxResult enableFurnitureType(@PathVariable Long typeId)
    {
        return toAjax(furnitureTypeService.enableFurnitureType(typeId));
    }

    /**
     * 禁用家具类型
     */
    @PreAuthorize("@ss.hasPermi('find:furnitureType:edit')")
    @Log(title = "家具类型", businessType = BusinessType.UPDATE)
    @PutMapping("/disable/{typeId}")
    public AjaxResult disableFurnitureType(@PathVariable Long typeId)
    {
        return toAjax(furnitureTypeService.disableFurnitureType(typeId));
    }
}